﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Reflection;
using System.Web;

namespace StudentOP
{
    public class MyContext:DbContext
    {
        //Code first 定义上下文
        public MyContext() : base("name=connstr")
        {

        }        

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //不使用modelBuilder.Configurations.AddFromAssembly方法则需要逐个添加,如果数量多的话比较麻烦
            //modelBuilder.Configurations.Add(new OneToMany.Map.ProductMap());
            //此方法可以将当前程序集下所有继承了ComplexTypeConfiguration、EntityTypeConfiguration类型的类添加到注册器

        //    base.OnModelCreating(modelBuilder);
            modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
        }

        public DbSet<ClassesEF> ClassEfModel { get; set; }
        public DbSet<StudentEF> StudentEfModel { get; set; }
        public object StuEntities { get; internal set; }
    }
}